package com.dikang.yygh.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.dikang.yygh.common.constant.MqConst;
import com.dikang.yygh.common.handler.HttpRequestHelper;
import com.dikang.yygh.common.result.Result;
import com.dikang.yygh.feign.MsmFeignClient;
import com.dikang.yygh.model.hosp.Department;
import com.dikang.yygh.model.hosp.Hospital;
import com.dikang.yygh.model.hosp.Schedule;
import com.dikang.yygh.service.DepartmentService;
import com.dikang.yygh.service.HospitalService;
import com.dikang.yygh.service.HospitalSetService;
import com.dikang.yygh.service.ScheduleService;
import com.dikang.yygh.vo.hosp.DepartmentVo;
import com.dikang.yygh.vo.hosp.HospitalQueryVo;
import com.dikang.yygh.vo.hosp.ScheduleOrderVo;
import com.dikang.yygh.vo.msm.MsmVo;
import com.dikang.yygh.vo.order.OrderMqVo;
import com.dikang.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Api(tags = "医院首页接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private HospitalSetService hospitalSetService;
    @Autowired
    private MsmFeignClient msmFeignClient;


    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Integer page,
                        @PathVariable Integer limit,
                        HospitalQueryVo hospitalQueryVo){
        // 显示上线的医院
        Page hospitalList = hospitalService.selectPage(page, limit, hospitalQueryVo);

        return Result.ok(hospitalList);
    }

    @ApiOperation(value = "根据医院名称获取医院列表")
    @GetMapping("findByHosname/{hosname}")
    public Result findByHosname(
            @ApiParam(name = "hosname", value = "医院名称", required = true)
            @PathVariable String hosname) {
        List<Hospital> hospitalList = hospitalService.getHospitalByHosname(hosname);

        return Result.ok(hospitalList);
    }
    @ApiOperation(value = "根据医院挂号详情")
    @GetMapping("{hoscode}")
    public Result findHospitalByhoscode(
            @PathVariable String hoscode
    ){
        Map<String, Object> show = hospitalService.item(hoscode);
        return Result.ok(show);
    }
    @ApiOperation(value = "根据医院挂号详情")
    @GetMapping("department/{hoscode}")
    public Result findDepartmentByhoscode(
            @PathVariable String hoscode
    ){
        List<DepartmentVo> departmentVos = departmentService.selectDepartmentByHoscode(hoscode);
        return Result.ok(departmentVos);
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result getScheduleDetail(
            @PathVariable String hoscode,
            @PathVariable String depcode,
            @PathVariable String workDate
    ){
        List<Schedule> list = scheduleService.getDetailSchedule(hoscode,depcode,new DateTime(workDate).toDate());
        return Result.ok(list);
    }
    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable String scheduleId) {
        return Result.ok(scheduleService.getById(scheduleId));
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }
    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);
    }









}
